import AttributeUtil from '@/AttributeUtil';
import SelectCommon from 'code/Core/Common/SelectCommon';
import SummonCommon from 'code/Core/Common/SummonCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 死亡骑士-操纵死尸
 */
export default class DK_ControlCorpse extends AbilityBase {
    static instance: DK_ControlCorpse;
    constructor(id: string) {
        super(id);
        DK_ControlCorpse.instance = this;
        se.onUnitSpellEffect(this.spellEffect.bind(this), this.id);
    }
    spellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let st = SelectCommon.getDeathUnitsInRange(GetUnitX(source), GetUnitY(source), 500);
        if (st.length == 0) return;
        let lv = this.getAbilityLevel(source);
        let count = Math.min(st.length, lv + 1 + ((AttributeUtil.getUnitAttribute(source)?.[this.id + '_effect_count'] as number) ?? 0));
        let fp = UnitCommon.getFullProperty(source);
        for (let i = 0; i < count; i++) {
            let id = id2string(GetUnitTypeId(st[i]));
            let [u] = SummonCommon.summon({
                caster: source,
                abilityId: this.id,
                unitTypeId: id,
                x: GetUnitX(st[i]),
                y: GetUnitY(st[i]),
                attr: {
                    life: fp * 0.7 * lv,
                    attack: (fp * lv) / 18 + 10 * lv,
                    附加护甲: (fp * lv) / 18 + 10 * lv,
                    附加魔抗: (fp * lv) / 18 + 10 * lv,
                },
                lifeTime: 35 + 5 * lv,
                effect: 'Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl',
            });
            SetUnitVertexColor(u, 255, 100, 100, 200);
            RemoveUnit(st[i]);
        }
    }
}
